var date=echartUtil.GetDateStr(0);
var startDay=echartUtil.GetDateStr(-30);
var deptId='';

//相关业务逻辑
$(function(){
	$("#yestarday").val(date);
	$("#startDay").val(startDay);
	nameToIdUtil.getProductionDepartment("productionDepartment");
	page.setReachKanBan(date);
	page.setDelayKanBan(date);
	page.setClockKanBan(date);
	page.getQualified(date);
	page.bind();
});


function dataChange(){
	startDay=$("#startDay").val();
	date=$("#yestarday").val();
	page.setReachKanBan(date,startDay);
	page.setDelayKanBan(date);
	page.setClockKanBan(date);
	page.getQualified(date);
}

var page={//页面总变量
		bind:function(){
			$("#productionDepartment").bind("change",function(){
				var deptIdThis=$("#productionDepartment").val();
				deptId=deptIdThis;
				page.setReachKanBan(date,startDay);
				page.setDelayKanBan(date);
				page.getQualified(date);
			});
		},
		//合格率看板
		setReachKanBan:function(date){
			$.ajax({
				url:'workshop/getTotal',
				data:{
					'date':date,
					'startDay':startDay,
					'deptId':deptId
				},
				success:function(data){
					if(data.result){
						data=data.data;
						var workShopArray=new Array();
						var workDataArray=new Array();
						for(var i=0;i<data.length;i++){
							workDataArray.push(data[i].reach);
							workShopArray.push(data[i].deptName);
						}
						echartUtil.barChartTemp('reachKanBan','达成率',['达成率'],workShopArray,workDataArray,'%');
					}
				}
			});
		},
		//拖期
		setDelayKanBan:function(date){
			$.ajax({
				url:"workshop/getOnTime",
				data:{
					'date':date,
					'deptId':deptId
				},
				success:function(data){
					if(data.result){
						var userArray=new Array();
						var userDataArray=new Array();
						data=data.data;
						for(var i=0;i<data.length;i++){
							userArray.push(data[i].deptName);
							userDataArray.push(data[i].reach);
						}
						echartUtil.barChartTemp('delayKanBan','车间准时率看板',['准时率'],userArray,userDataArray,'%');
					}else{
						layAlert(data.info);
					}
				}
			});
		},
		//周转量
//		getDeptTurnover:function(date){
//			$.ajax({
//				url:'workshop/getDeptTurnover',
//				data:{
//					'date':date
//				},
//				success:function(data){
//					if(data.result){
//						data=data.data;
//						var workShopArray=new Array();
//						var workDataArray=new Array();
//						for(var i=0;i<data.length;i++){
//							workShopArray.push(data[i].deptName);
//							workDataArray.push(data[i].reach);
//						}
//						echartUtil.barChartTemp('turnoverBar','车间周转量看板',['周转量'],workShopArray,workDataArray);
//						page.bind();
//					}else{
//						layAlert(data.info);
//					}
//				}
//			});
//		},
		getQualified:function(date){
			ajaxUtil.ajaxRuquest('workshop/getQualified',{'date':date,'deptId':deptId},function(data){
				var workShopArray=new Array();
				var workDataArray=new Array();
				for(var i=0;i<data.length;i++){
					workShopArray.push(data[i].deptName);
					workDataArray.push(data[i].reach);
				}
				echartUtil.barChartTemp('turnoverBar','车间合格率看板',['合格率'],workShopArray,workDataArray,'%');
			});
		},
		setClockKanBan:function(){
			$.ajax({
				url:'weiXin/getClock',
				success:function(data){
					if(data.result){
						data=data.data;
						var myChart = echarts.init(document.getElementById('clockKanBan'));
						 myChart.setOption({
							 title: {
						            text: '上下班打卡统计',
						            x:'center',
						            y: 'top'
						        },
							 tooltip: {
							        trigger: 'item',
							        formatter: "{a} <br/>{b}: {c} ({d}%)"
							    },
							    legend: {
							    	orient: 'horizontal',
							        x: 'center',
							        y: 'bottom',
							        data:['正常人数'+data.successUserCount,'异常人数'+data.errorUserCount]
							    },
							    series: [
							        {
							            name:'上班打卡',
							            type:'pie',
							            radius: ['50%', '60%'],
							            avoidLabelOverlap: false,
							            label: {
							                normal: {
							                    show: false,
							                    position: 'center'
							                },
							                emphasis: {
							                    show: true,
							                    textStyle: {
							                        fontSize: '30',
							                        fontWeight: 'bold'
							                    }
							                }
							            },
							            labelLine: {
							                normal: {
							                    show: true
							                }
							            },
							            data:[
							                {value:data.successUserCount, name:'正常人数'+data.successUserCount},
							                {value:data.errorUserCount, name:'异常人数'+data.errorUserCount}
							            ]
							        }
							    ]
						    });
					}

				}
			});
		}
}
//setInterval ("dataChange()", 900000);//十五分钟更新一次数据
